#include "rule.h"

Org::Rule::Rule()
{
    this->enabled = false;
    root_node = new Node();
}

Org::Rule::Rule(string name)
{
    this->rule_name = name;
    this->enabled = false;
    root_node = new Node();
}

Org::Rule::~Rule() {
   //delete(root_node);
}

bool Org::Rule::operator!=(Rule rule) {
    return !(this->operator==(rule));
}

bool Org::Rule::operator==(Rule rule)
{
    if( (this->action == rule.action) && (this->to_dir==rule.to_dir))
    {
        return *(this->root_node) == *(rule.root_node);
    }
    return false;
}

Org::Node::Node() {
    node_type = Vars::ORG_NO_NODE;
    operation = Vars::ORG_NO_OPERATION;
    search_type = Vars::ORG_NO_SEARCH_TYPE;
}

bool Org::Node::operator!=(Node node) {
    return !(this->operator==(node));
}

bool Org::Node::operator==(Node node)
{
    if (this->child_nodes.size() != node.child_nodes.size())
    {
        return false;
    }

    bool children_match = true;

    for (int i = 0; i < this->child_nodes.size(); i++)
    {
        children_match = this->child_nodes[i] == node.child_nodes[i];
        if (children_match == false) {
            return false;
        }
    }

    return  this->node_type == node.node_type &&
            this->operation == node.operation &&
            this->search_term == node.search_term &&
            this->search_in == node.search_in &&
            this->search_regex == node.search_regex &&
            this->search_type == node.search_type &&
            this->node_name == node.node_name;
}
